package com.aaa.medicine.controller;


import com.aaa.entity.Provider;
import com.aaa.entity.Purchase;
import com.aaa.medicine.service.IProviderService;
import com.aaa.medicine.service.IPurchaseService;
import com.aaa.medicine.vo.PurchaseVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王雪桂
 * @since 2023-03-29
 */
@RestController
@RequestMapping("medicine/purchase")
public class PurchaseController {
    @Autowired
    private IPurchaseService iPurchaseService;

    @GetMapping("getAll")
    public Result<Purchase> getAll(Page page,Purchase purchase,Integer dictValue){
        IPage<Purchase> all = iPurchaseService.getAll(page,purchase.getProviderId(),purchase.getApplyUserName(),purchase.getStatus());
        return new Result(all);
    }
    //提交审核
    @PostMapping("modification")
    public Result modification(@RequestBody PurchaseVo purchaseVo){
        purchaseVo.setStutas("2");
        iPurchaseService.modification(purchaseVo.getPurchaseId(),purchaseVo.getStutas());
        return new Result(200,"成功");
    }
    //作废
    @PostMapping("modification1")
    public Result modification1(@RequestBody PurchaseVo purchaseVo){
        purchaseVo.setStutas("5");
        iPurchaseService.modification(purchaseVo.getPurchaseId(),purchaseVo.getStutas());
        return new Result(200,"成功");
    }
    //提交入库
    @PostMapping("modification2")
    public Result modification2(@RequestBody PurchaseVo purchaseVo){
        purchaseVo.setStutas("6");
        iPurchaseService.modification(purchaseVo.getPurchaseId(),purchaseVo.getStutas());
        return new Result(200,"成功");
    }
    //供应商下拉框
    @Autowired
    private IProviderService iProviderService;
    @GetMapping("providerName")
    public Result<List<Provider>> providerName(){
        return new Result(iProviderService.list());
    }
}

